/*2S7LXljdWdGhrCxZ1MFl4nbo76lbmNV/zj9vAsZ4TsJjt35I/W4VBwuu/33I9fcb*/
import React, { Component } from 'react';
import { ajax, base, createPage, toast, sum, getMultiLang, formatNumber } from 'nc-lightapp-front';
import { buttonClick } from '../events';
import SupplementModel from '../supplementModel'; //补差模态框
import { accAdd } from '../../../public/components/method';
import { modifierSearchMetas } from '../../../public/components/pubUtils/arapVerificatRefFilter';
import SearchContions from '../../public/searchContions';
import { businessDate, getPreMonth, getPreMonthOne } from '../../../public/components/businessDate';
import { floatObj } from '../../../public/components/pubUtils/floatObj.js';
import { updatePaCFV } from '../../../public/components/pubUtils/updatePaCFV';
import { searchBtnClick } from '../../public/searchContions/events';

import './index.less';
const { NCSelect, NCForm, NCDiv, NCNumber } = base;
const NCFormItem = NCForm.NCFormItem;
const NCOption = NCSelect.NCOption;
let NCOptionData = [
	{ value: '0', display: '' } /* 国际化处理： 客户*/,
	{ value: '1', display: '' } /* 国际化处理： 供应商*/,
	{ value: '2', display: '' } /* 国际化处理： 部门*/,
	{ value: '3', display: '' } /* 国际化处理： 业务员*/
];
let transferData;
let verificationObjDis = null,
	objTypeValueDis = null;
let verificationObjVal = null,
	objTypeValueVal = null;
let tableid = 'table';
let pagecode = ''; //页面编码
let searchId = 'query';
let appcode = ''; //小应用编码
let pk_org; //财务组织
let billType; //单据类型
let businessDates, businessPreMonthDates, pageCode, appCode;

//获取并初始化模板
let initTemplate = (props, that) => {
	props.createUIDom(
		{
			pagecode: pagecode, //页面id
			appcode: appcode //注册按钮的id
		},
		function (data) {
			if (data) {
				if (data.template) {
					let meta = data.template;
					setDefObjSrchArea.call(that, props, searchId, data);
					meta = modifierMeta(props, meta);
					props.meta.oid = meta[searchId].oid;
					modifierSearchMetas(searchId, props, meta, billType, pk_org, that);
					props.meta.setMeta(meta);
				}
				if (data.button) {
					let button = data.button;
					props.button.setButtons(button);
				}
				
				if(transferData&&transferData!=undefined){
					let transfData=JSON.parse(JSON.stringify(transferData));
					that.transferData = transfData;
				}
				//设置查询区的默认带过来的字段值
				if(transferData&&transferData!=undefined){
					setQueryAreaData(that,transferData);
					that.isInit = true;
					searchBtnClick(that);
					setQueryAreaData(that,transferData);
				}
			}
		}
	);
};
function setDefObjSrchArea(props, searchId, data) {
	if (!props || !searchId || !data || !data.template) {
		return;
	}
	let ap = data.template.code.indexOf('2008') == 0;
	let ar = data.template.code.indexOf('2006') == 0;
	let objName = ap ? this.state.json['verificationsheet-000001'] : this.state.json['verificationsheet-000000'];
	let meta = data.template;
	let isNotNull = true;
	if(!transferData&&transferData==undefined){
        isNotNull = false;
	}
	let cuspDisplay = isNotNull==true?transferData.objTypeValue.display:null;
	let cuspValue = isNotNull==true?transferData.objTypeValue.value:null;
	let objtype = isNotNull==true? transferData.objtype.value:null;
	let objtypeName = isNotNull==true?transferData.objtype.display:null;
	let isnewSearch = false;
	if (data.template.query != null) {
		var queryschemes = data.template.query.queryschemes ? data.template.query.queryschemes : data.template.query.queryschemesdto;
		isnewSearch = true
	}
	var billdateInitialvalue = null;
	if (queryschemes != null && queryschemes.length > 0) {
		for (var k = 0; k < queryschemes.length; k++) {
			let queryscheme = isnewSearch ? queryschemes[k].querySchemeVO : queryschemes[k];
			if (queryscheme.isquickqs == true) {
				let renderobj4web = queryscheme.renderobj4web;
				if (renderobj4web != null && renderobj4web.length > 0) {
					for (var i = 0; i < renderobj4web.length; i++) {
						if (renderobj4web[i].attrcode == 'billdate') {
							billdateInitialvalue = renderobj4web[i].initialvalue;
							renderobj4web[i].visible = true;
							break;
						}
					}
				}
			}
		}
	}
	this.state.searchBilldate = billdateInitialvalue;

	meta[searchId].items.map((item) => {
		// if (item && (item.attrcode == 'objtype') && ap) {
		// 	item.initialvalue = { 'display': objName, 'value': "1" }
		// } else if (item && (item.attrcode == 'objtype') && ar) {
		// 	item.initialvalue = { 'display': objName, 'value': "0" }
		// } else if (item && (item.attrcode == 'customer' || item.attrcode == 'supplier')) {
		// 	//item.initialvalue = { 'display': cuspDisplay, 'value': cuspValue }
		// }
		
		if (item&&item.attrcode == 'billdate') {
            item.initialvalue = billdateInitialvalue;
		}
		
		if(objtype&&(objtype=="0"||objtype==0)){
			if(item.attrcode == 'supplier' || item.attrcode == 'pk_deptid' || item.attrcode == 'pk_psndoc'){
				item.visible =false;
			}
			if(item.attrcode == 'customer'){
				item.visible =true;
				item.initialvalue = { 'display': cuspDisplay, 'value': cuspValue }
			}
		}else if(objtype&&(objtype=="1"||objtype==1)){
			if(item.attrcode == 'customer' || item.attrcode == 'pk_deptid' || item.attrcode == 'pk_psndoc'){
				item.visible =false;
			}
			if(item.attrcode == 'supplier'){
				item.visible =true;
				item.initialvalue = { 'display': cuspDisplay, 'value': cuspValue }
			}
		}else if(objtype&&(objtype=="2"||objtype==2)){
			if(item.attrcode == 'supplier' || item.attrcode == 'customer' || item.attrcode == 'pk_psndoc'){
				item.visible =false;
			}
			if(item.attrcode == 'pk_deptid'){
				item.visible =true;
				item.initialvalue = { 'display': cuspDisplay, 'value': cuspValue }
			}
		}else if(objtype&&(objtype=="3"||objtype==3)){
			if(item.attrcode == 'supplier' || item.attrcode == 'customer' || item.attrcode == 'pk_deptid'){
				item.visible =false;
			}
			if(item.attrcode == 'pk_psndoc'){
				item.visible =true;
				item.initialvalue = { 'display': cuspDisplay, 'value': cuspValue }
			}
		}
		if(item.attrcode == 'objtype'){
			item.initialvalue = {'display': objtypeName, 'value': objtype } 
		}
	});
}

//对表格模板进行加工操作
function modifierMeta(props, meta) {
	meta[tableid].showindex = true; //表格显示序号
	meta[tableid].items = meta[tableid].items.map((item) => {
		if (item.attrcode == 'billno') {
			item.renderStatus = 'browse';
			item.render = (text, record) => {
				return (
					<a
						style={{ textDecoration: 'none', cursor: 'pointer' }}
						onClick={() => {
							billLink(record, props);
						}}
					>
						{record.values.billno.value}
					</a>
				);
			};
		}
		return item;
	});
	return meta;
}

//联查单据
function billLink(text, props) {
	ajax({
		url: '/nccloud/arap/arappub/linkarapbill.do',
		async: false,
		data: {
			tradeType: text.values.pk_tradetype.value,
			pk_bill: text.values.pk_bill.value
		},
		success: (res) => {
			props.openTo(res.data.url, res.data.condition);
		}
	});
}

function setQueryAreaData(that,transData){
	//设置表头查询区字段的值
	let WholeVerifyData =transData;// that.props.ViewModel.getData('WholeVerifyDatas');
	let objTypeData = WholeVerifyData.objtype;
	that.props.search.setSearchValByField(searchId, 'objtype',objTypeData);
	if(WholeVerifyData.objtype){
		if(WholeVerifyData.objtype.value){
			let objArry = ['customer', 'supplier','pk_deptid','pk_psndoc'];
			for(let i = 0;i<objArry.length;i++){
				if(i == Number(WholeVerifyData.objtype.value)){
					that.props.search.changeItemVisibleByField(searchId,objArry[i], true);
				}else{
					that.props.search.changeItemVisibleByField(searchId,objArry[i],false);
				}
			}
			if(WholeVerifyData.objtype.value=="0"||WholeVerifyData.objtype.value==0){
				that.props.search.setSearchValByField(searchId, 'customer', WholeVerifyData.objTypeValue);
			}else if(WholeVerifyData.objtype.value=="1"||WholeVerifyData.objtype.value==1){
				that.props.search.setSearchValByField(searchId, 'supplier', WholeVerifyData.objTypeValue);
			}else if(WholeVerifyData.objtype.value=="2"||WholeVerifyData.objtype.value==2){
				that.props.search.setSearchValByField(searchId, 'pk_deptid', WholeVerifyData.objTypeValue);
			}else if(WholeVerifyData.objtype.value=="3"||WholeVerifyData.objtype.value==3){
				that.props.search.setSearchValByField(searchId, 'pk_psndoc', WholeVerifyData.objTypeValue);
			}
		}
	}
}
class Cancellation extends Component {
	constructor(props) {
		super(props);
		this.oldVal = '';
		this.tableId = tableid;
		this.searchId = searchId;
		this.this_sett = '';
		this.defScale = '';
		this.transferDatas = {};
		this.state = {
			json: {},
			verificationObj: { display: '', value: '0' }, //核销对象/* 国际化处理： 客户*/
			objTypeValue: { display: null, value: null }, //核销对象值
			pk_tradetype: { display: null, value: null }, //交易类型
			value: [], //单据日期
			settlement: { display: null, value: null }, //结算金额
			dosettlement: { display: null, value: null },//结算金额，累计计算
			pk_org: null,
			isSupplementModelShow: false, //补差模态框
			modelData: {}, //加载模态框时的数据
			ts: null,
			scale: '',
			schemeData: {
				objType: { display: '', value: 0 }, //核销对象/* 国际化处理： 客户*/
				objTypeValue: { display: '', value: null }, //核销对象值
				pk_tradetype: { display: '', value: null }, //交易类型
				value: [] //单据日期
			},
			billno: null,
			totalSettle: null,//可结算总金额  !!!记录作用，除了第一次赋值，千万别动

			searchBilldate: null
		};
		this.handleSupplement = this.handleSupplement.bind(this);
		this.onAfterEvent = this.onAfterEvent.bind(this);
		this.dataInSaga = {    //用于saga里面的busiinfo
			appcode: props.getSearchParam('c') ? props.getSearchParam('c') : null,
			pagecode: props.getSearchParam('p') ? props.getSearchParam('p') : null,
			butncode: null
		}
		this.transferData = null;
		this.isInit = false;
		props.use.search(this.searchId);
		props.use.editTable(this.tableId);
	}

	componentWillMount() {
		window.onbeforeunload = () => {
			return '';
		};
		transferData = this.props.ViewModel.getData('WholeVerifyDatas');
		let isNotNull = true;
		if(!transferData||transferData==undefined){
			isNotNull = false;
		}
		this.state.billno = isNotNull==true? transferData['billno']:'';
		if (transferData != undefined) {
			verificationObjDis = transferData.objtype.display;
			verificationObjVal = transferData.objtype.value;
			objTypeValueDis = transferData.objTypeValue.display;
			objTypeValueVal = transferData.objTypeValue.value;
			pk_org = transferData.pk_org.value; //财务组织
			billType = transferData.billType.value; //单据类型
			this.setState({
				ts: transferData.ts.value,
				pk_org: pk_org
			});
		}
		initTemplate(this.props, this);
		pagecode = this.props.getSearchParam('p');
		appcode = this.props.getSearchParam('c');
		if (window.top === window.parent) {
			if (appcode != '20062002' && appcode != '20082002') {
				updatePaCFV(this, '#/nowv');
				pagecode = this.props.getSearchParam('p');
				appcode = this.props.getSearchParam('c');
			}
		}
		if (!window.top === window.parent) {
			pagecode = this.props.getUrlParam('pagecode');
			appcode = this.props.getUrlParam('appcode');
		}
		let callback = (json) => {
			NCOptionData = [
				{ value: '0', display: json['verificationsheet-000000'] } /* 国际化处理： 客户*/,
				{ value: '1', display: json['verificationsheet-000001'] } /* 国际化处理： 供应商*/,
				{ value: '2', display: json['verificationsheet-000002'] } /* 国际化处理： 部门*/,
				{ value: '3', display: json['verificationsheet-000003'] } /* 国际化处理： 业务员*/
			];
			this.setState({
				json: json,
				verificationObj: {
					display: verificationObjDis ? verificationObjDis : json['verificationsheet-000000'],
					value: verificationObjVal ? verificationObjVal : '0'
				},
				objTypeValue: {
					display: objTypeValueDis ? objTypeValueDis : '',
					value: objTypeValueVal ? objTypeValueVal : null
				}, //核销对象值
				schemeData: {
					objType: { display: json['verificationsheet-000000'], value: 0 }, //核销对象/* 国际化处理： 客户*/
					objTypeValue: { display: '', value: null }, //核销对象值
					pk_tradetype: { display: '', value: null }, //交易类型
					value: [] //单据日期
				}
			});
			if (transferData == undefined) {
				toast({
					duration: 3,
					color: 'warning',
					content: json['verificationsheet-000004'] /* 国际化处理： 刷新浏览器会清除数据，请关闭本页签，重新进入！*/
				});
			}
		};
		getMultiLang({
			moduleId: ['verificationsheet', 'public'],
			domainName: 'arap',
			currentLocale: 'simpchn',
			callback
		});
	}

	componentDidMount() {
		// let { value, schemeData } = this.state;
		// businessDates = businessDate();
		// businessPreMonthDates = getPreMonthOne(businessDates);
		// value = [businessPreMonthDates, businessDates];
		// schemeData.value = [businessPreMonthDates, businessDates];
		// this.setState({
		// 	value,
		// 	schemeData
		// });
		// if (transferData != undefined) {
		// 	// this.getData();
		// }
		pageCode = this.props.getUrlParam('transPageCode');
		appCode = this.props.getUrlParam('transAppCode');
		if (!window.top === window.parent) {
			//审批等状态下
			pageCode = this.props.getUrlParam('pagecode');
			appCode = this.props.getUrlParam('appcode');
		}
	}

	//获取模态框数据
	getModelData = (data) => {
		this.setState({
			modelData: data
		});
	};

	//请求列表数据
	getData = () => {
		//如果showOff为true，则显示停用数据，在请求参数data中增加显示停用参数，根据业务前后端自行处理
		let { ts, settlement } = this.state;
		let verifyConditionVO = {
			objType: verificationObjVal, //核销对象
			objTypeValue: transferData && transferData.objTypeValue.value, //核销对象值
			pk_tradetype: null, //交易类型
			beginDate: businessPreMonthDates, //开始日期
			endDate: businessDates //结束日期
		};
		let data = {
			queryTreeFormatVO: null,
			verifyConditionVO: verifyConditionVO,
			pageId: pagecode,
			pk_bill: transferData && transferData.pk_bill.value,
			pk_item: transferData && transferData.pk_item,
			billType: transferData && transferData.billType.value,
			ts: ts
		};
		ajax({
			url: '/nccloud/arap/billverify/nowVerifyQuery.do',
			data: data,
			success: (res) => {
				let { success, data } = res;
				if (success) {
					let datas = data.grid;
					this.state.ts = data.ts;
					this.defScale = data.scale;
					this.this_sett = this.handleAccuracy(data.this_sett, data.scale);
					this.state.settlement.value = this.handleAccuracy('0.000000000', data.scale);
					this.state.dosettlement.value = this.handleAccuracy(data.this_sett, data.scale);
					this.state.totalSettle = this.this_sett;
					this.setState(
						{
							settlement,
							ts
						},
						() => {
							this.getAccuracy(settlement, data.scale);
						}
					);
					if (datas && datas[tableid]) {
						this.props.editTable.setTableData(tableid, datas[tableid]);
					} else {
						this.props.editTable.setTableData(tableid, { rows: [] });
						this.props.button.setButtonDisabled('Share', true);
					}
				}
			}
		});
	};

	// 获取本次结算精度
	getAccuracy = (settlement, scale) => {
		let settlementVal = settlement.value;
		let scalel;
		if (settlementVal.indexOf('.') != -1) {
			scalel = settlementVal.split('.')[1].length;
		} else {
			scalel = scale;
		}
		this.setState({
			scale: scalel
		});
	};

	//点击查询按钮 重新渲染数据
	handleQueryBtn = () => {
		let { verificationObj, objTypeValue, pk_tradetype, value, ts } = this.state;
		let verifyConditionVO;
		if (value.length > 0) {
			verifyConditionVO = {
				objType: verificationObj.value, //核销对象
				objTypeValue: objTypeValue.value, //对象名称
				pk_tradetype: pk_tradetype.value, //交易类型
				beginDate: value[0], //开始时间
				endDate: value[1] //结束时间
			};
		} else {
			verifyConditionVO = {
				objType: verificationObj.value, //核销对象
				objTypeValue: objTypeValue.value, //对象名称
				pk_tradetype: pk_tradetype.value //交易类型
			};
		}
		let queryInfo = this.props.search.getQueryInfo(searchId);
		this.restverifyConditionVO(queryInfo, verifyConditionVO);
		let data = {
			pageId: pagecode,
			pk_bill: transferData.pk_bill.value,
			pk_item: transferData.pk_item,
			billType: transferData.billType.value,
			ts: ts,
			verifyConditionVO: verifyConditionVO
		};
		ajax({
			url: '/nccloud/arap/billverify/nowVerifyQuery.do',
			data: data,
			success: (res) => {
				let { success, data } = res;
				if (success) {
					let datas = data.grid;
					this.state.ts = data.ts;
					this.this_sett = this.handleAccuracy(data.this_sett, data.scale);
					this.state.settlement.value = this.handleAccuracy('0.0', data.scale);
					this.state.dosettlement.value = this.handleAccuracy(data.this_sett, data.scale);
					this.setState({
						ts
					});
					this.props.editTable.setStatus(tableid, 'browse');
					if (datas && datas[tableid]) {
						this.props.editTable.setTableData(tableid, datas[tableid]);
						this.props.button.setButtonDisabled('Share', false);
						toast({
							color: 'success',
							content:
								this.state.json['verificationsheet-000126'] +
								datas[tableid].rows.length +
								this.state.json['verificationsheet-000127']
						}); /* 国际化处理： 已成功共几条数据！*/
					} else {
						toast({
							color: 'warning',
							content: this.state.json['verificationsheet-000125']
						}); /* 国际化处理： 未查询出相应的数据！*/
						this.props.editTable.setTableData(tableid, {
							rows: []
						});
						this.props.button.setButtonDisabled('Share', true);
					}
				}
			},
			error: (res) => {
				this.props.editTable.setTableData(tableid, {
					rows: []
				});
			}
		});
	};
	restverifyConditionVO(queryInfo, verifyConditionVO) {
		let conditions = queryInfo.querycondition.conditions;
		// let { value ,schemeData} = that.state;
		let objtype = this.props.search.getSearchValByField(searchId, "objtype");
		var obj = null;
		if (objtype && objtype.value == 0||objtype.value.firstvalue==0) {
			obj = 'customer';
		} else if (objtype && objtype.value == 1||objtype.value.firstvalue==1) {
			obj = 'supplier';
		} else if (objtype && objtype.value == 2||objtype.value.firstvalue==2) {
			obj = 'pk_deptid';
		} else if (objtype && objtype.value == 3||objtype.value.firstvalue==3) {
			obj = 'pk_psndoc';
		}
		if (conditions && conditions.length > 0) {
			for (let i = 0; i < conditions.length; i++) {
				if (conditions[i].field == 'billdate') {
					verifyConditionVO.beginDate = conditions[i].value.firstvalue;
					verifyConditionVO.endDate = conditions[i].value.secondvalue;

				} else if (conditions[i].field == 'objtype') {
					verifyConditionVO.objType = conditions[i].value.firstvalue;
				} else if (conditions[i].field == obj) {
					verifyConditionVO.objTypeValue = conditions[i].value.firstvalue;
				} else if (conditions[i].field == 'pk_tradetype') {
					verifyConditionVO.pk_tradetype = conditions[i].value.firstvalue; //后台没支持多选交易类型，所以只能是一个
				}
			}
		}
	}

	//处理精度
	handleAccuracy = (str, s) => {
		let integer = str.split('.')[0];
		let decimal = str.split('.')[1].slice(0, Number(s));
		return integer + '.' + decimal;
	};

	//表格编辑后事件
	onAfterEvent(props, moduleId, key, changerows, value, index, data, a, b, c) {
		if (value[0].newvalue.value == value[0].oldvalue.value||this.isZero(value[0].newvalue)) {
			props.editTable.setValByKeyAndRowId(moduleId, data.rowid, 'this_sett', { value: 0.0,scale:this.scale});
			return;
		}
		let money_bal = data.values.money_bal.value;
		let newValue = floatObj.add(this.state.settlement.value, money_bal);
		let ceMoney = floatObj.subtract(value[0].newvalue.value, value[0].oldvalue.value);//大于0，改大，展示的结算变大，实际结算剩余变小；小于0 改小，展示结算变小，实际结算剩余变大；
		let settlementNew = { display: null, value: null }; //展示结算金额
		let dosettlementNew = { display: null, value: null }; //实际操作结算金额
		if (!this.scale) {
			this.scale = this.state.totalSettle.split('.')[1].length;
		}
		//计算出除当前操作的行外的其他所有选中行的本次结算总金额
		// let hascheckedSettleMny = this.handleAccuracy('0.00', this.scale);//不包含当前行的其他全部选中行结算金额
		// let checkRows = this.props.editTable.getCheckedRows(moduleId);
		// if(checkRows&&checkRows.length>1){
		// 	let  nowPK_busidata=data.values["pk_busidata"].value;
        //     for(let t=0;t<checkRows.length;t++){
		// 		let rowIndex=checkRows[t].index;
		// 		let nowRow_this_sett=checkRows[t].data.values["this_sett"].value;
		// 		let money_bal=checkRows[t].data.values["money_bal"].value;
		// 		if(rowIndex!=index){
		// 			if(floatObj.multiply(this.state.totalSettle,money_bal)<0){
		// 				hascheckedSettleMny = floatObj.subtract(hascheckedSettleMny, nowRow_this_sett);
		// 			}else{
		// 				hascheckedSettleMny = floatObj.add(hascheckedSettleMny, nowRow_this_sett);
		// 			}
		// 		}
		//     }
		// }
		if (key == 'this_sett') {
			if (money_bal < 0) {
				if (value[0].newvalue.value * 1 >= money_bal * 1 && value[0].newvalue.value * 1 < 0) {
                    //目前还剩的可结算金额
					// let doSettle = floatObj.subtract(this.state.totalSettle, hascheckedSettleMny);
					// if(floatObj.multiply(this.state.totalSettle,money_bal)<0){
					// 	if(Number(doSettle)>=0){
					// 		props.editTable.setValByKeyAndRowId(tableid, data.rowid, 'this_sett', {
					// 			value: value[0].newvalue.value,scale:this.scale
					// 		});
					// 	}else{
					// 		props.editTable.setValByKeyAndRowId(tableid, data.rowid, 'this_sett', {
					// 			value: 0.0,scale:this.scale
					// 		});
					// 	}
					// }else{
					// 	if(Number(doSettle)>=0){
					// 		props.editTable.setValByKeyAndRowId(tableid, data.rowid, 'this_sett', {
					// 			value: 0.0,scale:this.scale
					// 		});
					// 	}else{
					// 		props.editTable.setValByKeyAndRowId(tableid, data.rowid, 'this_sett', {
					// 			value: value[0].newvalue.value,scale:this.scale
					// 		});
					// 	}
					// }
					props.editTable.setValByKeyAndRowId(tableid, data.rowid, 'this_sett', {
						value: Number(value[0].newvalue.value),scale:this.scale
					});

				} else {
					props.editTable.setValByKeyAndRowId(moduleId, data.rowid, 'this_sett', { value: 0.0,scale:this.scale});
				}
			} else {
				if (value[0].newvalue.value * 1 > 0 && value[0].newvalue.value * 1 <= money_bal * 1) {
					//目前还剩的可结算金额
					// let doSettle = floatObj.subtract(this.state.totalSettle, hascheckedSettleMny);
					// if(floatObj.multiply(this.state.totalSettle,money_bal)<0){
					// 	if(Number(doSettle)>=0){
					// 		props.editTable.setValByKeyAndRowId(tableid, data.rowid, 'this_sett', {
					// 			value: 0.0,scale:this.scale
					// 		});
					// 	}else{
					// 		props.editTable.setValByKeyAndRowId(tableid, data.rowid, 'this_sett', {
					// 			value: value[0].newvalue.value,scale:this.scale
					// 		});
					// 	}
					// }else{
					// 	if(Number(doSettle)>=0){
					// 		props.editTable.setValByKeyAndRowId(tableid, data.rowid, 'this_sett', {
					// 			value: value[0].newvalue.value,scale:this.scale
					// 		});
					// 	}else{
					// 		props.editTable.setValByKeyAndRowId(tableid, data.rowid, 'this_sett', {
					// 			value: 0.0,scale:this.scale
					// 		});
					// 	}
					// }
					props.editTable.setValByKeyAndRowId(tableid, data.rowid, 'this_sett', {
						value: Number(value[0].newvalue.value),scale:this.scale
					});

				} else {
					props.editTable.setValByKeyAndRowId(moduleId, data.rowid, 'this_sett', { value: 0.0,scale:this.scale});
				}
			}

			let selectedData = this.props.editTable.getCheckedRows(tableid);
			let sumSettlMny={ display: null, value: null };
			let checkedRowsSettleMny = this.handleAccuracy('0.00', this.scale)
			if(selectedData!=null&&selectedData.length>0){
                for(let i=0;i<selectedData.length;i++){
					 let mny=selectedData[i].data.values.this_sett.value;
					 //sumSettlMny.value=floatObj.add(sumSettlMny.value,mny);
					 if(floatObj.multiply(this.state.totalSettle,mny)<0){
						 checkedRowsSettleMny = floatObj.subtract(checkedRowsSettleMny, mny);
					 }else{
						 checkedRowsSettleMny = floatObj.add(checkedRowsSettleMny, mny);
					 }
				}
				sumSettlMny.value = checkedRowsSettleMny;
				if(Math.abs(sumSettlMny.value)>Math.abs(this.state.totalSettle)){
					dosettlementNew.value=this.handleAccuracy('0.0', this.scale);
					settlementNew.value=this.state.totalSettle;
				}else{
					dosettlementNew.value= floatObj.subtract(this.state.totalSettle,sumSettlMny.value);
					settlementNew.value=sumSettlMny.value;
				}
			}

			this.setState({ settlement: settlementNew, dosettlement: dosettlementNew })
		}
	}

	//补差按钮弹出模态框
	handleSupplement = () => {
		this.transferDatas = this.getVerifyNowData();
		this.props.ViewModel.setData('transferCardData', this.transferDatas);
	};

	//清空按钮
	handleEmpty = () => {
		let { objTypeValue, pk_tradetype, value } = this.state;
		objTypeValue = { display: null, value: null };
		pk_tradetype = { display: null, value: null };
		value = [];
		this.setState({
			objTypeValue,
			pk_tradetype,
			value
		});
	};

	//修改高级查询常用条件
	handleAddAdvBodyCons = (schemeData) => {
		this.setState({
			schemeData: schemeData
		});
	};

	//分摊按钮
	handleShare = () => {
		let allDatas = this.props.editTable.getAllRows(tableid, true);
		let { settlement, dosettlement } = this.state;
		if(this.isZero(settlement)||(this.isZero(dosettlement)&&floatObj.subtract(settlement.value,this.state.totalSettle)!=0)){
			toast({
					color: 'warning',
					content: this.state.json['verificationsheet-000143'] /* 国际化处理： 请注意！本次结算金额不能大于可结算金额！*/
				});
			return;
		}
		let settlementNew = settlement.value.toString().replace('-', '');
		let dosettlementNew = dosettlement.value.toString().replace('-', '');
		let brrIndex = [];
		let len = allDatas.length;
		for (var j = 0; j < len; j++) {
			allDatas[j].values.this_sett = { value: this.handleAccuracy('0.0', this.scale) };
			this.props.editTable.setValByKeyAndRowId(tableid, allDatas[j].rowid, 'this_sett',  {value: 0.0,scale:this.scale});
			brrIndex.push(j);
		}
		setTimeout(() => {
			this.props.editTable.selectTableRows(tableid, brrIndex, false);
		}, 0);
		for (var i = 0; i < len; i++) {
			let this_sett = allDatas[i].values.money_bal.value.replace('-', '');
			let this_sett_t = allDatas[i].values.money_bal.value;
			if (settlementNew.indexOf('-') == -1) {
				if (sum(this_sett, '-' + settlementNew).indexOf('-') == -1) {
					allDatas[i].values.this_sett = { value: this_sett_t > 0 ? Number(settlementNew).toString() : '-' + Number(settlementNew).toString() };
					settlementNew = sum(settlementNew, '-' + this_sett);
				} else {
					allDatas[i].values.this_sett = { value: this_sett_t };
					settlementNew = sum(settlementNew, '-' + this_sett);
				}
			}
		}
		let arrIndex = [];
		for (var i = 0; i < len; i++) {
			if (allDatas[i].values.this_sett.value * 1 != 0) {
				arrIndex.push(i);
			}
		}
		if (!this.scale) {
			this.scale = this.state.totalSettle.split('.')[1].length;
		}
		for (var i = 0; i < len; i++) {
			if (allDatas[i].values.this_sett.value) {
				let settleMny = allDatas[i].values.this_sett.value;
				if(settleMny!=null&&settleMny!=''&&Number(settleMny)!=0){
					this.props.editTable.setValByKeyAndRowId(tableid, allDatas[i].rowid, 'this_sett', {
						value: allDatas[i].values.this_sett.value,scale:this.scale
					});
				}else{
					this.props.editTable.setValByKeyAndRowId(tableid, allDatas[i].rowid, 'this_sett', {
						value: 0.0,scale:this.scale
					});
				}
			}
		}
		setTimeout(() => {
			this.props.editTable.setStatus(tableid, 'edit');
			//this.props.editTable.setEditableRowKeyByIndex(tableid, arrIndex, 'this_sett', true);
			this.props.editTable.selectTableRows(tableid, arrIndex, true);
			let allData = this.props.editTable.getAllRows(tableid, true);
			for (var i = 0; i < len; i++) {
				if(allData[i].selected==false){
					this.props.editTable.setEditableRowKeyByIndex(tableid, allData[i].index, 'this_sett', false);
				}else{
					this.props.editTable.setEditableRowKeyByIndex(tableid,  allData[i].index, 'this_sett', true);
				}
			}
		}, 0);
		// dosettlement.value = floatObj.subtract(dosettlementNew, settlement.value);
		// // if( floatObj.subtract(dosettlementNew, settlement.value);dosettlement.value){
		// // 	dosettlement.value = 0
		// // }
		// this.setState({ dosettlement: dosettlement })
		toast({
			duration: 3,
			color: 'success',
			content: this.state.json['verificationsheet-000145'] /* 国际化处理： 分摊成功！*/
		});
	};

	
	//获取选中行数据
	getCheckedDatas = () => {
		let linkVOs = [];
		let editTableData = this.props.editTable.getCheckedRows(tableid);
		for (var i = 0, len = editTableData.length; i < len; i++) {
			let objTypeValue;
			let DataValues = editTableData[i].data.values;
			let objtype = DataValues.objtype.value;
			if (objtype == 0) {
				objTypeValue = DataValues.customer.value;
			} else if (objtype == 1) {
				objTypeValue = DataValues.supplier.value;
			} else if (objtype == 2) {
				objTypeValue = DataValues.pk_deptid.value;
			} else if (objtype == 3) {
				objTypeValue = DataValues.pk_psndoc.value;
			}
			let o = {
				pk_bill: editTableData[i].data.values.pk_bill.value,
				pk_item: (editTableData[i].data.values.pk_item && editTableData[i].data.values.pk_item.value) || '',
				billType: editTableData[i].data.values.pk_billtype.value,
				this_sett: editTableData[i].data.values.this_sett.value,
				objTypeValue: objTypeValue
			};
			linkVOs.push(o);
		}
		return linkVOs;
	};

	//获取及时核销数据
	getVerifyNowData = () => {
		let { settlement } = this.state;
		let editTableData = this.props.editTable.getCheckedRows(tableid);
		let this_sett_sum = 0;
		let len = editTableData.length;
		for (var i = 0; i < len; i++) {
			this_sett_sum = accAdd(this_sett_sum, Math.abs(editTableData[i].data.values.this_sett.value * 1));
		}
		let linkVOs = [];
		if (Math.abs(settlement.value) != this_sett_sum) {
			for (var i = 0; i < len; i++) {
				let objTypeValue;
				let DataValues = editTableData[i].data.values;
				let objtype = DataValues.objtype.value;
				if (objtype == 0) {
					objTypeValue = DataValues.customer.value;
				} else if (objtype == 1) {
					objTypeValue = DataValues.supplier.value;
				} else if (objtype == 2) {
					objTypeValue = DataValues.pk_deptid.value;
				} else if (objtype == 3) {
					objTypeValue = DataValues.pk_psndoc.value;
				}
				let o = {
					pk_bill: editTableData[i].data.values.pk_bill.value,
					pk_item: (editTableData[i].data.values.pk_item && editTableData[i].data.values.pk_item.value) || '',
					billType: editTableData[i].data.values.pk_billtype.value,
					this_sett: editTableData[i].data.values.this_sett.value,
					linkedPk: editTableData[i].data.values.linkedPk.value,
					objTypeValue: objTypeValue
				};
				linkVOs.push(o);
			}
			this.setState({
				isSupplementModelShow: !this.state.isSupplementModelShow
			}, () => {
				if (this.state.isSupplementModelShow) {
					this.child.modalOpen();
				} else {
					this.child.modalClose();
				}

			});
		} else {
			toast({
				duration: 3,
				color: 'warning',
				title: this.state.json['verificationsheet-000006'] /* 国际化处理： 请注意*/,
				content: this.state.json['verificationsheet-000099'] /* 国际化处理： 传入数据的本方金额和对方金额的绝对值相等！*/
			});
			return;
		}
		let data = {
			pageId: this.props.getSearchParam('p'), //页面编码
			pk_bill: transferData.pk_bill.value, //单据主键
			pk_item: transferData.pk_item, //按表体核销时，设置行主键
			billType: transferData.billType.value, //单据类型
			ts: transferData.ts.value, //表头ts
			this_sett: settlement.value, //核销金额
			linkVOs: linkVOs //选中数据
		};
		return data;
	};

	onRenderNow = (ref) => {
		this.child = ref;
	}
	//即时核销按钮
	handleCancellation = () => {
		let { settlement } = this.state;
		let checkRows = this.props.editTable.getCheckedRows(tableid);
		if(this.isZero(settlement)){
			toast({
				duration: 3,
				color: 'danger',
				content: this.state.json['verificationsheet-000144'] /* 国际化处理： 本次核销金额为0，操作失败！*/
			});	
		}
		if(checkRows&&checkRows.length==0){
			toast({
				duration: 3,
				color: 'danger',
				content: this.state.json['verificationsheet-000146'] /* 表体行未勾选，请先勾选表体再进行操作！*/
			});	
			return;
		}
		let editTableData = this.props.editTable.getCheckedRows(tableid);
		let len = editTableData.length;
		let this_sett_sum = '';
		for (var i = 0; i < len; i++) {
			this_sett_sum = sum(this_sett_sum, editTableData[i].data.values.this_sett.value.toString().replace('-', ''));
		}

		if (Number(settlement.value.toString().replace('-', '')) == Number(this_sett_sum.replace(/\,/g, ''))) {
			let linkVOs = [];
			for (var i = 0; i < len; i++) {
				let objTypeValue;
				let DataValues = editTableData[i].data.values;
				let objtype = DataValues.objtype.value;
				if (objtype == 0) {
					objTypeValue = DataValues.customer.value;
				} else if (objtype == 1) {
					objTypeValue = DataValues.supplier.value;
				} else if (objtype == 2) {
					objTypeValue = DataValues.pk_deptid.value;
				} else if (objtype == 3) {
					objTypeValue = DataValues.pk_psndoc.value;
				}
				let o = {
					pk_bill: editTableData[i].data.values.pk_bill.value,
					pk_item: (editTableData[i].data.values.pk_item && editTableData[i].data.values.pk_item.value) || '',
					billType: editTableData[i].data.values.pk_billtype.value,
					this_sett: editTableData[i].data.values.this_sett.value,
					linkedPk: editTableData[i].data.values.linkedPk.value,
					objTypeValue: objTypeValue
				};
				if(this.isZero(editTableData[i].data.values.this_sett)){
					continue;
				}
				linkVOs.push(o);
			}
			let data = {
				pageId: this.props.getSearchParam('p'), //页面编码
				pk_bill: transferData.pk_bill.value, //单据主键
				pk_item: transferData.pk_item, //按表体核销时，设置行主键
				billType: transferData.billType.value, //单据类型
				ts: this.state.ts, //表头ts
				this_sett: settlement.value, //核销金额
				linkVOs: linkVOs //选中数据
			};
			let scene = this.props.getUrlParam('scene');
			let parameter =
				'appcode=' +
				appCode +
				'&pagecode=' +
				pageCode +
				'&c=' +
				appCode +
				'&p=' +
				pageCode +
				'&scene=' +
				scene +
				'&id=' +
				transferData.pk_bill.value +
				'&status=browse';
			ajax({
				url: '/nccloud/arap/billverify/nowVerify.do',
				data: Object.assign(data, this.dataInSaga),
				success: (res) => {
					let { success } = res;
					if (success) {
						// if (window.top === window.parent) {
							this.props.pushTo('/card', {
								id: transferData.pk_bill.value, //单据主键
								pagecode: pageCode,
								appcode: appCode,
								p: pageCode,
								c: appCode,
								status: 'browse'
							});
						// } else {
						// 	window.location.hash = '/card?' + parameter;
						// 	window.parent.location.hash = '/card?' + parameter;
						// }
					}
				}
			});
		} else {
			toast({
				duration: 3,
				color: 'warning',
				title: this.state.json['verificationsheet-000006'] /* 国际化处理： 请注意*/,
				content: this.state.json['verificationsheet-000007'] /* 国际化处理： 传入数据的本方金额和对方金额的绝对值不相等！*/
			});
		}
	};
	/**
		 * Number(settlement.value.replace('-', '')) == Number(this_sett_sum.replace(/\,/g, ''))
		 * @param {*} props 
		 * @param {*} moduleId 
		 * @param {*} tableMoney 
		 * @param {*} headMoney 
		 * @param {*} showMoney 
		 * @param {*} index 
		 * @param {*} mode 模式：1 表体正数，可结算负数；2，表体正数，可结算正数；3表体负数，可结算负数;4表体负数，可结算正数
		 * @param {*} flag   flag>0 表体大于表头绝对值。 
		 */
	doBusiLinkMoney(props, moduleId, tableMoney, headMoney, showMoney, index, mode, flag) {
		let allCheckedData = this.props.editTable.getAllRows(moduleId, true);//选中数据
		let settlementNew = { display: null, value: null }; //展示结算金额
		let dosettlementNew = { display: null, value: null }; //实际操作结算金额
		let settleMoney = this.handleAccuracy('0.0', this.scale);
		if (mode == 1) {
			settlementNew.value = flag > 0 ? floatObj.subtract(0, headMoney) : floatObj.add(tableMoney, headMoney);
			dosettlementNew.value = flag > 0 ? this.handleAccuracy('0.0', this.scale) : floatObj.add(tableMoney, headMoney);
			settleMoney = flag > 0 ? floatObj.subtract(0, headMoney) : tableMoney;
		} else if (mode == 2) {
			settlementNew.value = flag > 0 ? floatObj.add(showMoney, headMoney) : floatObj.add(showMoney, tableMoney);
			dosettlementNew.value = flag > 0 ? this.handleAccuracy('0.0', this.scale) : floatObj.subtract(headMoney, tableMoney);
			settleMoney = flag > 0 ? headMoney : tableMoney;
		} else if (mode == 3) {//此场景不存在
			settlementNew.value = flag > 0 ? headMoney : tableMoney;
			dosettlementNew.value = flag > 0 ? this.handleAccuracy('0.0', this.scale) : floatObj.subtract(tableMoney, headMoney);
			settleMoney = flag > 0 ? headMoney : tableMoney;
		} else if (mode == 4) {
			let dotableMoney = floatObj.subtract(0,tableMoney);
			settlementNew.value = flag > 0 ? floatObj.add(showMoney, headMoney) : floatObj.add(showMoney, dotableMoney);
			dosettlementNew.value = flag > 0 ? this.handleAccuracy('0.0', this.scale) : floatObj.add(tableMoney, headMoney);
			settleMoney = flag > 0 ? floatObj.subtract(0, headMoney) : tableMoney;
		} else {

		}
		props.editTable.setValByKeyAndRowId(tableid, allCheckedData[index].rowid, 'this_sett', {
			value: settleMoney,scale:this.scale
		});
		this.checkSettleMoney(settlementNew ,dosettlementNew,moduleId);


	}
	//点击单个选择框函数
	onSelectedFn = (props, moduleId, record, index, status) => {
		this.state.totalSettle = this.this_sett;
		let allCheckedData = this.props.editTable.getAllRows(moduleId, true);//选中数据
		let this_sett = record.values.money_bal.value;//表体行本次结算金额
		//let head_this_sett = this.state.dosettlement.value;//表头右上角参与计算的金额
		
		let head_this_sett_total = this.state.settlement.value;//表头右上角展示的金额
		let checkRows = this.props.editTable.getCheckedRows(moduleId);
		if(this.state.settlement.value==null||(status&&checkRows&&checkRows.length==1)){
			head_this_sett_total=this.handleAccuracy('0.00', this.scale);
			this.state.dosettlement.value =  this.state.totalSettle ;
		}
		// let head_this_sett = floatObj.subtract(this.state.totalSettle,head_this_sett_total);

		// let flag = Number(this_sett.replace('-', '')) - (this.isZero(this.state.dosettlement) ? 0 : Number(this.state.dosettlement.value.toString().replace(/\,/g, '')));//绝对值
		
		let checkedRowsSettleMny = this.handleAccuracy('0.00', this.scale);//不包含当前行的其他全部选中行结算金额
		if(checkRows&&checkRows.length>1){
			let  nowPK_busidata=record.values["pk_busidata"].value;
            for(let t=0;t<checkRows.length;t++){
			   let pk_busidata=checkRows[t].data.values["pk_busidata"].value;
			   let nowRow_this_sett=checkRows[t].data.values["this_sett"].value;
			   let money_bal=checkRows[t].data.values["money_bal"].value;
			   if(nowPK_busidata!=pk_busidata){
				    if(floatObj.multiply(this.state.totalSettle,money_bal)<0){
						checkedRowsSettleMny = floatObj.subtract(checkedRowsSettleMny, nowRow_this_sett);
					}else{
						checkedRowsSettleMny = floatObj.add(checkedRowsSettleMny, nowRow_this_sett);
					}
			   }
		   }
		}
		if(floatObj.subtract(checkedRowsSettleMny,"0.0")!=0){
			if(this.handleAccuracy(this.state.totalSettle, this.scale)>0){
                if(floatObj.subtract(checkedRowsSettleMny,this.state.totalSettle) >=0){
					//head_this_sett_total= this.handleAccuracy(this.state.totalSettle, this.scale);
					this_sett = this.handleAccuracy('0.00', this.scale);
				}
			}else{
				if(floatObj.subtract(checkedRowsSettleMny,this.state.totalSettle) <=0){
					//head_this_sett_total= this.handleAccuracy(this.state.totalSettle, this.scale);
					this_sett = this.handleAccuracy('0.00', this.scale);
				}
			}
		}
		let head_this_sett = floatObj.subtract(this.handleAccuracy(this.state.totalSettle, this.scale),head_this_sett_total);
		let flag = floatObj.subtract(this_sett.toString().replace('-', ''),this.state.dosettlement.value.toString().replace('-', ''));//this_sett2 -this_dosettlement;
		
		if (!this.scale) {
			this.scale = this_sett.split('.')[1].length;
		}
		if (status) {//勾选
			props.editTable.setStatus(tableid, 'edit');
			let mode = 0;
			if (this_sett > 0 && head_this_sett < 0) {
				mode = 1;
			} else if (this_sett > 0 && head_this_sett > 0) {
				mode = 2;
			} else if (this_sett < 0 && head_this_sett < 0) {
				mode = 3;
			} else if (this_sett < 0 && head_this_sett > 0) {//实际等于0的场景
				mode = 4;
			} else if (head_this_sett == 0) {
				props.editTable.setEditableRowKeyByIndex(tableid, index, 'this_sett', true);
				// props.editTable.setValByKeyAndRowId(tableid, allCheckedData[index].rowid, 'this_sett', {
				// 	value: this.handleAccuracy('0.0', this.scale)
				// });
				props.editTable.setValByKeyAndRowId(tableid, allCheckedData[index].rowid, 'this_sett', {
					value: 0.0,scale:this.scale
				});
				return;
			}
			this.doBusiLinkMoney(props, moduleId, this_sett, head_this_sett, head_this_sett_total, index, mode, flag);
			props.editTable.setEditableRowKeyByIndex(tableid, index, 'this_sett', true);
		} else {//取消勾选
			// 表头  表体： 正数-正数，正数-负数，负数-正数，负数-负数
			let settlementNew = { display: null, value: null }; //展示结算金额
			let dosettlementNew = { display: null, value: null }; //实际操作结算金额
			let this_index_settle = props.editTable.getValByKeyAndRowId(tableid, allCheckedData[index].rowid, 'this_sett').value;
			if(this_index_settle==null){
				this_index_settle = this.handleAccuracy('0.0', this.scale);
			}
			//let cancelflag = Number(this_index_settle.replace('-', '')) - Number(head_this_sett.replace(/\,/g, ''))>0;//绝对值
			//props.editTable.setValByKeyAndRowId(tableid, allCheckedData[index].rowid, 'this_sett', { value: this.handleAccuracy('0.0', this.scale) });
			props.editTable.setValByKeyAndRowId(tableid, allCheckedData[index].rowid, 'this_sett', {
				value: 0.0,scale:this.scale
			});
			props.editTable.setEditableRowKeyByIndex(tableid, index, 'this_sett', false);
			if (this_index_settle >= 0) {
				if (head_this_sett >= 0) {
					dosettlementNew.value = floatObj.add(head_this_sett, this_index_settle)
					settlementNew.value = floatObj.subtract(head_this_sett_total, this_index_settle) < 0 ? this.handleAccuracy('0.0', this.scale) : floatObj.subtract(head_this_sett_total, this_index_settle);
				} else {
					settlementNew.value = floatObj.add(head_this_sett_total, this_index_settle) > 0 ? this.handleAccuracy('0.0', this.scale) : floatObj.add(head_this_sett_total, this_index_settle);
					dosettlementNew.value = floatObj.subtract(head_this_sett, this_index_settle);
				}
			} else {
				if (head_this_sett >= 0) {
					settlementNew.value = floatObj.add(head_this_sett_total, this_index_settle) > 0 ? this.handleAccuracy('0.0', this.scale) : floatObj.add(head_this_sett_total, this_index_settle);
					dosettlementNew.value = floatObj.subtract(head_this_sett, this_index_settle);
				} else {
					dosettlementNew.value = floatObj.add(head_this_sett, this_index_settle)
					settlementNew.value = floatObj.subtract(head_this_sett_total, this_index_settle) < 0 ? this.handleAccuracy('0.0', this.scale) : floatObj.subtract(head_this_sett_total, this_index_settle);
				}
			}
			if (floatObj.subtract(dosettlementNew.value, this.state.totalSettle) > 0) {
				dosettlementNew.value = this.state.totalSettle
				this.setState({ settlement: settlementNew })
				this.setState({ dosettlement: dosettlementNew })
				// toast({
				// 	color: 'warning',
				// 	content: this.state.json['verificationsheet-000141'] /* 国际化处理： 请注意！本次结算金额不能大于可结算金额！*/
				// });
			}
			props.editTable.setStatus(tableid, 'browse');
			//this.setState({ settlement: settlementNew, dosettlement: dosettlementNew })
			this.checkSettleMoney(settlementNew ,dosettlementNew,moduleId);
		}
		//全部遍历列表数据：不选中的行的结算金额全部设置为0
		for(let i = 0;i<allCheckedData.length;i++){
			if(allCheckedData[i].selected==false){
				props.editTable.setValByKeyAndRowId(tableid, allCheckedData[i].rowid, 'this_sett', {value: 0.0,scale:this.scale});
				props.editTable.setEditableRowKeyByIndex(moduleId, allCheckedData[i].index, 'this_sett', false);
			}else{
				props.editTable.setEditableRowKeyByIndex(moduleId, allCheckedData[i].index, 'this_sett', true);
			}
		}
		//关于界面编辑态的处理：有选中行时设置为编辑态
		let checkData = this.props.editTable.getCheckedRows(moduleId);
		if(checkData&&checkData.length>0){
			props.editTable.setStatus(moduleId, 'edit');
		}else{
			props.editTable.setStatus(moduleId, 'browse');
		}
	};

	//全选按钮回调
	onSelectedAllFn = (props, moduleId, status, length) => {
		this.state.totalSettle = this.this_sett;
		let allCheckedData = this.props.editTable.getAllRows(moduleId, true);
		let arrIndex = [];
		//let settlementNew = { display: null, value: this.state.settlement.value }; //展示结算金额
		//let dosettlementNew = { display: null, value: this.state.dosettlement.value}; //实际操作结算金额
		let settlementNew = { display: null, value: this.handleAccuracy('0.0', this.scale)}; //展示结算金额
		let dosettlementNew = { display: null, value: this.handleAccuracy(this.state.totalSettle, this.scale) }; //实际操作结算金额
		let settleMoney = this.handleAccuracy('0.0', this.scale);
		if (!this.scale) {
			this.scale = this.state.totalSettle.split('.')[1].length;
		}
		//清空所有行的本次结算金额
		for (var i = 0; i < length; i++) {
			props.editTable.setValByKeyAndRowId(tableid, allCheckedData[i].rowid, 'this_sett', {value: 0.0,scale:this.scale});
		}
		if (status) {
			for (var i = 0; i < length; i++) {
				props.editTable.setEditableRowKeyByIndex(tableid, i, 'this_sett', true);
				let showMoney = settlementNew.value;//表头结算展示金额  应该用累加法计算展示金额
				let headMoney = dosettlementNew.value;//表头结算实际计算金额
				//let showMoney = this.handleAccuracy('0.0', this.scale);
				//let headMoney = this.handleAccuracy(this.state.totalSettle, this.scale);
				let tableMoney = allCheckedData[i].values.money_bal.value;//本次勾选的
				//let flag = Number(tableMoney.replace('-', '')) - (this.isZero(dosettlementNew) ? 0 : Number(dosettlementNew.value.toString().replace(/\,/g, '')));//绝对值
				//let rowid = allCheckedData[i].rowid;
				if(this.isZero(dosettlementNew)){
					break;
				}
				arrIndex.push(i);
				// if (Number(tableMoney.replace('-', '')) == flag) {
				// 	continue;
				// }

                 //计算当前遍历行本次结算金额
				if (tableMoney > 0 && this.state.totalSettle < 0){
                    if(Math.abs(tableMoney)>=Math.abs(headMoney)){
					    settleMoney = Math.abs(headMoney);
						settlementNew.value = this.state.totalSettle;
						dosettlementNew.value = this.handleAccuracy('0.0', this.scale);
					}else{
						settleMoney = tableMoney;
						settlementNew.value = floatObj.subtract(settlementNew.value, settleMoney);
						dosettlementNew.value = floatObj.subtract(this.state.totalSettle, settlementNew.value);
					}
				} else if (tableMoney > 0 && this.state.totalSettle > 0){
					if(Math.abs(tableMoney)>=Math.abs(headMoney)){
					    settleMoney = Math.abs(headMoney);
						settlementNew.value = this.state.totalSettle;
						dosettlementNew.value = this.handleAccuracy('0.0', this.scale);
					}else{
						settleMoney = tableMoney;
						settlementNew.value = floatObj.add(settlementNew.value, settleMoney);
						dosettlementNew.value = floatObj.subtract(this.state.totalSettle, settlementNew.value);
					}
				} else if (tableMoney < 0 && this.state.totalSettle < 0){
					if(Math.abs(tableMoney)>=Math.abs(headMoney)){
					    settleMoney = headMoney;
						settlementNew.value = this.state.totalSettle;
						dosettlementNew.value = this.handleAccuracy('0.0', this.scale);
					}else{
						settleMoney = tableMoney;
						settlementNew.value = floatObj.add(settlementNew.value, settleMoney);
						dosettlementNew.value = floatObj.subtract(this.state.totalSettle, settlementNew.value);
					}
				} else if (tableMoney < 0 && this.state.totalSettle > 0){
					if(Math.abs(tableMoney)>=Math.abs(headMoney)){
					    settleMoney = floatObj.subtract(0, headMoney);
						settlementNew.value = this.state.totalSettle;
						dosettlementNew.value = this.handleAccuracy('0.0', this.scale);
					}else{
						settleMoney = tableMoney;
						settlementNew.value = floatObj.subtract(settlementNew.value, settleMoney);
						dosettlementNew.value = floatObj.subtract(this.state.totalSettle, settlementNew.value);
					}
				} else if(headMoney==0||Number(headMoney)==0){
                    props.editTable.setEditableRowKeyByIndex(tableid, i, 'this_sett', true);
					props.editTable.setValByKeyAndRowId(tableid, allCheckedData[i].rowid, 'this_sett', {
						value: 0.0,scale:this.scale
					});
				}

				props.editTable.setValByKeyAndRowId(tableid, allCheckedData[i].rowid, 'this_sett', {
					value: settleMoney,scale:this.scale
				});

				
				// if (tableMoney > 0 && headMoney < 0) {
				// 	settlementNew.value = flag > 0 ? floatObj.subtract(0, headMoney) : floatObj.add(tableMoney, headMoney);
				// 	dosettlementNew.value = flag > 0 ? this.handleAccuracy('0.0', this.scale) : floatObj.add(tableMoney, headMoney);
				// 	settleMoney = flag > 0 ? floatObj.subtract(0, headMoney) : tableMoney;
				// } else if (tableMoney > 0 && headMoney > 0) {
				// 	settlementNew.value = flag > 0 ? floatObj.add(showMoney, headMoney) : floatObj.add(showMoney, tableMoney);
				// 	dosettlementNew.value = flag > 0 ? this.handleAccuracy('0.0', this.scale) : floatObj.subtract(headMoney, tableMoney);
				// 	settleMoney = flag > 0 ? headMoney : tableMoney;
				// } else if (tableMoney < 0 && headMoney < 0) {//此场景不存在
				// 	settlementNew.value = flag > 0 ? headMoney : tableMoney;
				// 	dosettlementNew.value = flag > 0 ? this.handleAccuracy('0.0', this.scale) : floatObj.subtract(tableMoney, headMoney);
				// 	settleMoney = flag > 0 ? headMoney : tableMoney;
				// } else if (tableMoney < 0 && headMoney > 0) {
				// 	let dotableMoney = floatObj.subtract(0,tableMoney);
				// 	settlementNew.value = flag > 0 ? floatObj.add(showMoney, headMoney) : floatObj.add(showMoney, dotableMoney);
				// 	dosettlementNew.value = flag > 0 ? this.handleAccuracy('0.0', this.scale) : floatObj.add(tableMoney, headMoney);
				// 	//settlementNew.value = settlementNew.value<0?floatObj.subtract(0, settlementNew.value):settlementNew.value
				// 	settleMoney = flag > 0 ? floatObj.subtract(0, headMoney) : tableMoney;
				// }else if (headMoney == 0) {
				// 	props.editTable.setEditableRowKeyByIndex(tableid, i, 'this_sett', true);
				// 	// props.editTable.setValByKeyAndRowId(tableid, allCheckedData[i].rowid, 'this_sett', {
				// 	// 	value: this.handleAccuracy('0.0', this.scale),scale:this.scale
				// 	// });
				// 	props.editTable.setValByKeyAndRowId(tableid, allCheckedData[i].rowid, 'this_sett', {
				// 		value: 0.0,scale:this.scale
				// 	});
				// 	return;
				// }
				// props.editTable.setValByKeyAndRowId(tableid, allCheckedData[i].rowid, 'this_sett', {
				// 	value: settleMoney,scale:this.scale
				// });
			}
			this.checkSettleMoney(settlementNew ,dosettlementNew,moduleId);
			props.editTable.setEditableRowKeyByIndex(tableid, arrIndex, 'this_sett', true);
		} else {
			settlementNew.value = this.handleAccuracy('0.0', this.scale);
			dosettlementNew.value = this.handleAccuracy(this.state.totalSettle, this.scale);
			this.checkSettleMoney(settlementNew ,dosettlementNew,moduleId);
			// props.editTable.setStatus(tableid, 'browse');
			// for (var i = 0; i < length; i++) {
			// 	props.editTable.setEditableRowKeyByIndex(tableid, i, 'this_sett', false);
			// }
		}
		//关于界面编辑态的处理：有选中行时设置为编辑态
		let checkData = this.props.editTable.getCheckedRows(moduleId);
		if(checkData&&checkData.length>0){
			props.editTable.setStatus(tableid, 'edit');
		}else{
			props.editTable.setStatus(tableid, 'browse');
		}
		//关于行本次结算金额编辑性设置：选中行可编辑，不选中行不可编辑
		let allData = this.props.editTable.getAllRows(moduleId, true);//所有列表行数据
		for(let index = 0;index<allData.length;index++){
			if(allData[index].selected==false){
				props.editTable.setEditableRowKeyByIndex(moduleId, index, 'this_sett', false);
			}else{
				props.editTable.setEditableRowKeyByIndex(moduleId, index, 'this_sett', true);
			}
		}
	};
	/**
	 * 
	 * @param {*} settlementNew  展示金额，最大不超过可结算金额
	 * @param {*} dosettlementNew 实际参与计算金额，最小不小于0
	 */
	checkSettleMoney=(settlementNew,dosettlementNew,moduleId)=>{
		let settle = Number(settlementNew?settlementNew.value:this.handleAccuracy('0.0', this.scale));
		let dosettle = Number(dosettlementNew?dosettlementNew.value:this.handleAccuracy('0.0', this.scale));
		let oriSettle = Number(this.state.totalSettle);
		if((oriSettle>0&&(settle<0||settle>oriSettle))||(oriSettle<0&&(settle>0||settle<oriSettle))){
		  settlementNew.value = this.handleAccuracy('0.0', this.scale);
		}
		if((oriSettle>0&&(dosettle<0||dosettle>oriSettle))||(oriSettle<0&&(dosettle>0||dosettle<oriSettle))){
		  dosettlementNew.value = this.handleAccuracy('0.0', this.scale);
		}

		//计算所有当前选中的行的本次结算金额
		let checkRows = this.props.editTable.getCheckedRows(moduleId);
		let checkedRowsSettleMny = this.handleAccuracy('0.00', this.scale);//全部选中行结算金额
		if(checkRows&&checkRows.length>0){
			for(let t=0;t<checkRows.length;t++){
				let nowRow_this_sett=checkRows[t].data.values["this_sett"].value;
				let money_bal=checkRows[t].data.values["money_bal"].value;
				if(floatObj.multiply(this.state.totalSettle,money_bal)<0){
				checkedRowsSettleMny = floatObj.subtract(checkedRowsSettleMny, nowRow_this_sett);
				}else{
					checkedRowsSettleMny = floatObj.add(checkedRowsSettleMny, nowRow_this_sett);
				}
			}
		}
		let sumSett = checkedRowsSettleMny;//当前选中的全部本次结算金额
		settlementNew.value = sumSett;
		dosettlementNew.value = floatObj.subtract( this.state.totalSettle,sumSett);
		if(floatObj.subtract(sumSett, "0.0")!=0){
			if(this.handleAccuracy(this.state.totalSettle, this.scale)>0){
				if(floatObj.subtract(sumSett, this.state.totalSettle)>=0){
					settlementNew.value = this.state.totalSettle;
					dosettlementNew.value = this.handleAccuracy('0.00', this.scale);
				}
			}else{
				if(floatObj.subtract(sumSett, this.state.totalSettle)<=0){
					settlementNew.value = this.state.totalSettle;
					dosettlementNew.value = this.handleAccuracy('0.00', this.scale);
				}
			}
		}

		this.setState({ settlement: settlementNew, dosettlement: dosettlementNew })
		

  }
	isZero(this_row_settle) {
		if (!this_row_settle||!this_row_settle.value) {
			return true;
		}
		if (parseInt(this_row_settle.value) != this_row_settle.value) {
			let value = typeof (this_row_settle.value) == 'string' ? this_row_settle.value.split('.') : this_row_settle.value.toString().split('.');
			if (value && value.length == 2) {
				let scal = this.scale;
				const arr = new Array(scal).fill('0');
				let zero = arr.toString();
				if (value[0] == 0 && value[1] == zero) {
					return true;
				} else {
					return false;
				}
			} else {
				return true;
			}
		} else {
			if (this_row_settle.value == 0) {
				return true;
			} else {
				return false;
			}
		}
	}

	//返回按钮
	handleBack = () => {
		let id = transferData ? transferData.pk_bill.value : '',
			scene = this.props.getUrlParam('scene'),
			transAppCode = transferData.appcode,
			transPageCode = transferData.pageId;
		let parameter =
			'appcode=' +
			transAppCode +
			'&c=' +
			transAppCode +
			'&pagecode=' +
			transPageCode +
			'&id=' +
			id +
			'&scene=' +
			scene +
			'&status=browse';
		// if (window.top === window.parent) {
			if (transferData != undefined) {
				this.props.pushTo('/card', {
					pagecode: transPageCode,
					appcode: transAppCode,
					id: id,
					scene: scene,
					status: 'browse'
				});
			}
		// } else {
		// 	window.location.hash = '/card?' + parameter;
		// 	window.parent.location.hash = '/card?' + parameter;
		// }
	};
	// 自定义展示区
	renderExtensionArea = () => {
		let { settlement,dosettlement,totalSettle} = this.state;
		return (
			<div className="extention-area">
				<div className="extention-item nc-theme-common-font-c">
					<span className='extention-item-title'>{this.state.json['verificationsheet-000012']}：</span>
					<span className="nc-theme-title-font-c">{formatNumber(this.this_sett)}</span>
				</div>
				{/* 国际化处理： 可结算*/}
				<div className='extention-item'>
					<span className='extention-item-title'>{this.state.json['verificationsheet-000010']}</span> {/* 国际化处理： 本次结算：*/}
					<div>
						<NCNumber
							fieldid="financeNum"
							style={{ 'text-align': 'left' }}
							// className="bill-instruction-input"
							value={settlement.value}
							scale={this.defScale}
							onBlur={(v) => {
								if (this.this_sett * 1 > 0) {
									if (v >= this.this_sett * 1 || v < 0) {
										settlement.value = this.this_sett;
									}
								}
								if (this.this_sett * 1 < 0) {
									if (v > 0 || v <= this.this_sett * 1) {
										settlement.value = this.this_sett;
									}
								}
								this.setState({
									settlement
								});
							}}
							onChange={(v) => {
								settlement.value = Number(v).toString();
								dosettlement.value = floatObj.subtract(totalSettle,v)
							}}
						/>
					</div>
				</div>
			</div>
		)
	}
	render() {
		let { button, search, editTable } = this.props;
		let { NCCreateSearch } = search;
		let { createEditTable } = editTable;
		let { createButtonApp } = button;
		const NCOptions = NCOptionData.map((province) => <NCOption value={province}>{province.display}</NCOption>);

		const { createBillHeadInfo } = this.props.BillHeadInfo;
		return (
			<div id="RelationNowId" className='nc-bill-list'>
				<NCDiv areaCode={NCDiv.config.HEADER} className="nc-bill-header-area relation-tit nc-theme-common-header-bgc">
					<div className="header-title-search-area">
						{createBillHeadInfo({
							title: this.state.json['verificationsheet-000100'] + ' : ' + this.state.billno,//国际化处理： 即时核销
							backBtnClick: () => {
								this.handleBack();
							}
						})}
					</div>
					<div className="title-right">
						{/* 自定义展示区 */}
						{this.renderExtensionArea()}
						<div>
							{createButtonApp({
								area: 'list_head',
								buttonLimit: 4,
								onButtonClick: buttonClick.bind(this)
								//popContainer: document.querySelector('.header-button-area')
							})}
						</div>
					</div>
				</NCDiv>
				{/* 查询区 */}
				{SearchContions(this, NCOptions, createButtonApp, NCCreateSearch, searchId)}
				{/* 表格区 */}
				<div className={'nc-bill-table-area'}>
					{createEditTable(tableid, {
						//列表区
						fieldid: "verifynow",
						onAfterEvent: this.onAfterEvent, // 控件的编辑后事件
						useFixedHeader: true,
						onSelected: this.onSelectedFn, // 左侧选择列单个选择框回调
						onSelectedAll: this.onSelectedAllFn, // 左侧选择列全选回调
						showCheck: true, //显示复选框
						adaptionHeight: true,
						showIndex:true
					})}
				</div>
				<SupplementModel
					show={this.state.isSupplementModelShow}
					handleModel={this.handleSupplement}
					modelData={this.state.modelData}
					makeUpSelectData={this.getCheckedDatas()}
					transferCardData={this.transferDatas}
					createButtonApp={createButtonApp}
					onRef={this.onRenderNow}
				/>
			</div>
		);
	}
}

Cancellation = createPage({
	mutiLangCode: ''
})(Cancellation);

export default Cancellation;

/*2S7LXljdWdGhrCxZ1MFl4nbo76lbmNV/zj9vAsZ4TsJjt35I/W4VBwuu/33I9fcb*/